﻿function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + ";";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}



function eraseCookie(name) {
    createCookie(name, "", -1);
}

function OpenWindow(url, name, w, h, scrollbar, resizable) {
    var settings = "'width=" + w + ",height=" + h + ",scrollbars=" + scrollbar + ",resizable=" + resizable + ",screenX=200,screenY=200'";
    window.open(url, name, settings);

}

/*String Utilities*/
function RemoveDangerousHTMLTag(text) {
    var pattern1 = /<script[^>]*>.*?<\/script>/ig;
    var pattern2 = /<iframe[^>]*>.*?<\/iframe>/ig;
    var pattern3 = /<style[^>]*>.*?<\/style>/ig;
    var pattern4 = /<link[^>]*>.*?\/>/ig;
    text = text.replace(pattern1, '').replace(pattern2, '').replace(pattern3, '').replace(pattern4, '');
    return text;
}
function HtmlDecode(textDeco) {
    var resultText = textDeco;
    resultText = replaceAll(resultText, "&lt;", "<");
    resultText = replaceAll(resultText, "&gt;", ">");
    resultText = replaceAll(resultText, "&quot;", '"');
    resultText = replaceAll(resultText, "&amp;", "&");
    return resultText;
}
// function HtmlDecode (textDeco) {
//    var resultText = textDeco;
//    resultText = replaceAll(resultText, "\r", "");
//    resultText = replaceAll(resultText, "\n", "<br>");
////    resultText = encodeURIComponent(resultText);
//    return resultText;
//}

function replaceAll(strSource, strTarget, strSubString) {
    var strText = strSource;
    var intIndexOfMatch = strText.indexOf(strTarget);

    while (intIndexOfMatch != -1) {
        strText = strText.replace(strTarget, strSubString)
        intIndexOfMatch = strText.indexOf(strTarget);
    }
    return strText;
}

function removeDoubleLine(str) {
    //IE
    while (str.indexOf("\r\n\r\n") >= 0) {
        str = str.replace(/\r\n\r\n/g, "\r\n")
    }
    //FF
    while (str.indexOf("\n\n") >= 0) {
        str = str.replace(/\n\n/g, "\n")
    }
    return str;
}

function disableEnterKey(e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox

    return (key != 13);
} 
